<template>
  <a-modal :visible="currentVisible" width="40%" centered :footer="null" @cancel="currentVisible = false">
    <a-carousel ref="acarousel" class="acarousel" arrows :dots="false" style="margin-top: 20px" :afterChange="afterChangeHandle">
      <div slot="prevArrow" class="custom-slick-arrow" style="left: 10px; zIndex: 1">
        <a-icon type="left" class="center" />
      </div>
      <div slot="nextArrow" class="custom-slick-arrow" style="right: 10px">
        <a-icon type="right" class="center" />
      </div>
      <img ref="imglist" class="img-item" v-for="item in imgs" :key="item" :src="item" alt="" />
    </a-carousel>
    <div class="self-dots">{{ `${currentIndex}/${imgs.length}` }}</div>
  </a-modal>
</template>
<script>
import { Swiper, SwiperSlide } from 'vue-awesome-swiper'
import 'swiper/css/swiper.css'
export default {
  props: {
    current: {
      type: Number,
      default: 1
    },
    visible: {
      type: Boolean,
      default: false
    },
    imgs: {
      type: Array,
      default: () => []
    }
  },
  components: {
    Swiper,
    SwiperSlide
  },
  data() {
    return {
      currentIndex: 1
    }
  },
  watch: {
    visible: {
      immediate: true,
      handler: function(value) {
        if (value) {
          this.$nextTick(function() {
            this.$refs.acarousel.goTo(this.$props.current, true)
            this.currentIndex = this.$props.current + 1
          })
        }
      }
    }
  },

  computed: {
    currentVisible: {
      get() {
        return this.visible
      },
      set(val) {
        this.$emit('update:visible', val)
      }
    }
  },
  methods: {
    afterChangeHandle(current) {
      this.currentIndex = current + 1
      console.log(current)
    },
    close() {
      this.$emit('close')
    }
  }
}
</script>
<style scoped>
.center {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  color: #1890ff;
  font-size: 16px;
}
.center:hover {
}
.self-dots {
  text-align: center;
}
.ant-carousel >>> .slick-slide {
  text-align: center;
  /* height: 300px; */
  /* line-height: 300px; */
  background: #364d79;
  overflow: hidden;
}

.ant-carousel >>> .custom-slick-arrow {
  width: 25px;
  height: 25px;
  font-size: 25px;
  color: #000;
  background-color: rgba(31, 45, 61, 0.11);
  text-align: center;
  line-height: 17px;
  /* opacity: 0.3; */
}
.ant-carousel >>> .custom-slick-arrow:before {
  display: none;
}
.ant-carousel >>> .custom-slick-arrow:hover {
  opacity: 0.5;
}
.ant-carousel >>> .slick-slide {
  background: none !important;
}
.ant-carousel >>> .slick-slide h3 {
  color: #fff;
}
.img-item {
  height: auto;
  width: 100%;
}
</style>

